import 'dart:async';

import 'package:dio/dio.dart';
import 'package:enter_prise_web/routes/app_routes.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SplashPage extends StatefulWidget {
  const SplashPage({super.key});

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  var _version = "1.0.0";
  var _savePath = "";
  double _value = 0.0;

  @override
  void initState() {
    super.initState();
    startTime();
  }

 


  Timer? _timer;
  int count = 3;
  @override
  Widget build(BuildContext context) {
    return Material(
      child: Stack(
        children: [
          SizedBox(
              width: double.infinity,
              height: double.infinity,
              child:
                  Image.asset('assets/images/splash.jpg', fit: BoxFit.cover)),

          // Add your logo or text here
          const Padding(
            padding: EdgeInsets.only(bottom: 300.0),
            child: Center(
                child: Text('欣全鑫管理系统',
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: 24,
                        fontWeight: FontWeight.bold))),
          ),

          Positioned(
            top: 20,
            right: 20,
            child: Container(
              width: 80,
              decoration: BoxDecoration(
                color: Colors.black.withOpacity(0.1),
                borderRadius: BorderRadius.circular(5),
              ),
              padding: const EdgeInsets.all(8),
              child: GestureDetector(
                onTap: () {
                  navigationPage();
                },
                child: Center(
                    child: Text(
                  "跳过 $count",
                  style: TextStyle(
                      fontSize: 17, color: Colors.white.withOpacity(0.5)),
                )),
              ),
            ),
          )
        ],
      ),
    ); // Replace with your splash image
  }

  startTime() async {
    var duration = const Duration(seconds: 1);
    Timer(duration, () {
      _timer = Timer.periodic(const Duration(milliseconds: 1000), (timer) {
        count--;
        if (count == 0) {
          navigationPage();
        } else {
          setState(() {});
        }
      });
    });
  }

  void navigationPage() {
    _timer?.cancel();
    // Navigator.of(context).pushReplacementNamed("firstPage");
    Get.offNamed(Routes.index);
  }
}
